import * as globalTypes from '../../../mutation-types'
// import * as types from './mutation-types'
import robotConfig from '../../../api/config/robot-config'

export const robotInformationSel = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.robotInformationSel(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

export const robotInformation = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.robotInformation(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

export const queryQustionType = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryQustionType(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const delQuesType = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.delQuesType(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addQuesType = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.addQuesType(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const updateQuesType = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.updateQuesType(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryQuestions = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryQuestions(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const intelligentStudyQuerys = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.intelligentStudyQuerys(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const unknownStudyQueryQuestions = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.unknownStudyQueryQuestions(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const disabledQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.disabledQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const activeQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.activeQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const moveQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.moveQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const deleteQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.deleteQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getStudyQuestionById = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.getStudyQuestionById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const ignoreQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.ignoreQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const passQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.passQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const exportQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.exportQuestion(data)
    .then(response => {
      if (response.success) {
        commit(globalTypes.SET_FILEDOWNLOAD, { path: response.path, isSession: true })
      }
    })
    .catch(() => {
    })
}
export const unknownStudyIgnore = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.unknownStudyIgnore(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryQuestionAnswerDetail = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryQuestionAnswerDetail(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getRobotXlsHeads = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.getRobotXlsHeads(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const importRobotQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.importRobotQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addquestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.addQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const unknownRelevanceQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.unknownRelevanceQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const relevanceStudyQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.relevanceStudyQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const getQuestionById = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.getQuestionById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const updateQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.updateQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addUnknowQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.addUnknowQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addStudyQuestion = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.addStudyQuestion(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const queryUserDictionary = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryUserDictionary(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const addUserDictionary = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.addUserDictionary(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const deleteUserDictionary = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.deleteUserDictionary(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
export const updateUserDictionary = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.updateUserDictionary(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 获取风控 登录sessionId
export const m7RiskLogin = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.m7RiskLogin(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 获取AIRobot 登录token
export const m7AiRobotLogin = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.m7AiRobotLogin(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 获取是否开启小七
export const queryRobotConfig = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryRobotConfig(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// 获取AIRobot列表
export const queryM7AIRobot = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.queryM7AIRobot(data)
    .then(response => {
      if (response && response.success && response.data) {
        response.data.forEach((item) => {
          if (item.Status) {
            console.log(item.Status)
            item.disabled = false
          } else {
            item.disabled = true
          }
        })
      }
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
// xbot机器人
export const xbotRobotConfig = ({commit, state, rootState, dispatch}, data) => {
  return robotConfig.xbotRobotConfig(data)
    .then(response => {
      return response
    })
}
// xbot机器人创建账户
export const xbotCreateAccount = ({commit, state, rootState, dispatch}, data) => {
  let account = {account: rootState.session.account.account}
  return robotConfig.xbotCreateAccount(account)
    .then(response => {
      return response
    })
}
